import request from '@/utils/axios'
import qs from 'qs'

export type MyNotifyType = {
  id: number
  userId: number
  userType: number
  templateId: number
  templateCode: string
  templateNickname: string
  templateContent: string
  templateType: number
  templateParams: string
  readStatus: boolean
  readTime: Date
  create_time?: Date
}

export interface MyNotifyPageReqType extends PageParam {
  readStatus?: boolean
  create_time?: Date[]
}

/**
 * 消息中心 - 站内信管理 - 我的站内信消息记录接口
 */
export const MyNotifyApi = {
  // 查询分页列表
  page: (params: MyNotifyPageReqType) => {
    return request.get({ url: '/system/notify-record/my-page', params, is_mock: true })
  },
  // 批量标记已读
  read: (ids: number | number[]) => {
    return request.put({ url: '/system/notify-record/update-read?' + qs.stringify({ ids: ids }, { indices: false }), is_mock: true })
  },
  // 标记所有已读
  allRead: () => {
    return request.put({ url: '/system/notify-record/update-all-read', is_mock: true })
  },
  // 获取当前用户未读站内信
  unread: () => {
    return request.get({ url: '/system/notify-record/get-unread-list', is_mock: true })
  },
  // 获取当前用户未读站内信数量
  unreadCount: () => {
    return request.get({ url: '/system/notify-record/get-unread-count', is_mock: true, is_loading: false })
  }
}
